package com.iwhalecloud.bss.kite.cucc.service.pos.handler.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.pos.handler.IKitePosSceneHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;

public abstract class KitePosSceneHandler implements IKitePosSceneHandler {

	protected String getAttrValue(List<KiteAttr> developerAttrs, String fieldName, String errorMsg) {
		List<KiteAttr> attrs = developerAttrs.stream().filter((attr) -> fieldName.equals(attr.getFieldName())).collect(Collectors.toList());
		if (KiteListUtils.isEmpty(attrs)) {
			//ErrorConsts.BUSI_COMMON_ERROR.throwOut(errorMsg);
		    return "";
		}
		KiteAttr attr = attrs.get(0);
		if ("F".equals(attr.getIsNull()) && KiteStringUtils.isEmpty(attr.getValue())) {
			//ErrorConsts.BUSI_COMMON_ERROR.throwOut("属性值不能为空：" + attr.getCname());
		}

		return attr.getValue() != null ? attr.getValue() : "";
	}

	protected String getAttrOriginValueValue(List<KiteAttr> developerAttrs, String fieldName, String errorMsg) {
		List<KiteAttr> attrs = developerAttrs.stream().filter((attr) -> fieldName.equals(attr.getFieldName())).collect(Collectors.toList());
		if (KiteListUtils.isEmpty(attrs)) {
			//ErrorConsts.BUSI_COMMON_ERROR.throwOut(errorMsg);
		    return "";
		}
		KiteAttr attr = attrs.get(0);
		if ("F".equals(attr.getIsNull()) && KiteStringUtils.isEmpty(attr.getOriginValue())) {
			//ErrorConsts.BUSI_COMMON_ERROR.throwOut("属性值不能为空：" + attr.getCname());
		}

		return attr.getOriginValue() != null ? attr.getOriginValue() : "";
	}

}
